package study.dyproxy.jdk.echo;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

@Slf4j
public class EchoHandler implements InvocationHandler {

    /* 被代理的对象，实际的方法执行者 */
    private Object target;

    public EchoHandler(Object obj) {
        this.target = obj;
    }

    /**
     * @param proxy  -Object: 代理对象
     * @param method -Method:
     * @param args   -Object[]: 参数
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //
        log.info(">>> before invoke {}", method.getName());
        Object result = method.invoke(target, args);
        log.info(">>> after invoke {}", method.getName());
        return result;
    }
}
